﻿
@inject NavigationManager NavigationManager
@inject IHttpService _httpService

<MDialog @bind-Value="Dialog"
         Width="800">
    <MDCard>
        <MCardTitle Class="text-h5">
            完善度明细
        </MCardTitle>
        <MCardText>
            更新会有一天左右的延迟
        </MCardText>
        <Scroll style="max-height:600px;" class="ps-6 pe-6">
            @if (isReady)
            {
                <MExpansionPanels @bind-Values="panel" Class="mt-2 mb-2" Multiple>
                    @if (Model.Any(s => s.Level == PerfectionCheckLevel.High))
                    {
                        <MExpansionPanel>
                            <MExpansionPanelHeader>
                                急需完善
                            </MExpansionPanelHeader>
                            <MExpansionPanelContent>
                                @foreach (var item in Model.Where(s => s.Level == PerfectionCheckLevel.High))
                                {
                                    <PerfectionCheckAloneViewTip Model="@item"></PerfectionCheckAloneViewTip>
                                }
                            </MExpansionPanelContent>
                        </MExpansionPanel>
                    }
                    <MExpansionPanel>
                        <MExpansionPanelHeader>
                            待完善
                        </MExpansionPanelHeader>
                        <MExpansionPanelContent>
                            @foreach (var item in Model.Where(s => s.Level != PerfectionCheckLevel.High && s.Level != PerfectionCheckLevel.None))
                            {
                                <PerfectionCheckAloneViewTip Model="@item"></PerfectionCheckAloneViewTip>
                            }
                        </MExpansionPanelContent>
                    </MExpansionPanel>
                    <MExpansionPanel>
                        <MExpansionPanelHeader>
                            已完善
                        </MExpansionPanelHeader>
                        <MExpansionPanelContent>
                            @foreach (var item in Model.Where(s => s.Level == PerfectionCheckLevel.None))
                            {
                                <PerfectionCheckAloneViewTip Model="@item"></PerfectionCheckAloneViewTip>
                            }
                        </MExpansionPanelContent>
                    </MExpansionPanel>
                </MExpansionPanels>
            }
            else
            {
                <CnGalWebSite.Components.Progressings.ProgressingCard />

            }


        </Scroll>
       
        <MCardActions Class="pb-6 pe-6 ps-6 pt-6">
            <MSpacer></MSpacer>
            <CnGalWebSite.Components.Buttons.MasaButton Text="查看编辑指引" OnClick="@(()=>NavigationManager.NavigateTo("/perfections/home"))" Icon="mdi-share-all-outline" Color="success" TextStyle/>
        </MCardActions>
    </MDCard>
</MDialog>

@code {

    public long PerfectionId { get; set; }
    [Parameter]
    public List<PerfectionCheckViewModel> Model { get; set; } = new List<PerfectionCheckViewModel>();

    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }

    bool Dialog { get; set; }

    public string Text { get; set; }
    bool isReady = false;
    List<StringNumber> panel = new List<StringNumber> { 1, 2, 3 };

    protected async Task Init()
    {
        try
        {
            Model = await _httpService.GetAsync<List<PerfectionCheckViewModel>>("api/perfections/GetEntryPerfectionCheckList/" + PerfectionId);

            panel.Clear();
            if(Model.Any(s => s.Level == PerfectionCheckLevel.High))
            {
                panel.Add(0);
            }
            else
            {
                panel.Add(0);
                panel.Add(1);
            }


            isReady = true;
            StateHasChanged();
        }
        catch (Exception ex)
        {
            await ErrorHandler.ProcessError(ex, "获取词条完善度明细列表失败");
        }
    }

    public async Task Refresh(bool dialog, long id)
    {
        Dialog = dialog;
        PerfectionId = id;
        isReady = false;

        StateHasChanged();

        await Init();

        StateHasChanged();
    }
}
